solidity |
您所在的位置:网站首页 › solidity struct › solidity |
自定义结构体。 struct Custom{ bool myBool; uint myInt; }结构体内部不可以嵌套。 struct Custom{ bool myBool; uint myInt; Custom c; }上面的写法是错误的,但是下面的写法是可以的。 struct Custom{ mapping(string => Custom) indexs; }声明与初始化 仅声明变量,不初始化 Custom c; 按成员顺序初始化 Custom c = Custom(true,2); 如果结构体成员里面有 mapping 初始化的时候要跳过 struct Custom{ bool myBool; mapping(address => uint) balance; uint myInt; }初始化 Custom c = Custom(true,2); // 跳过 mapping命名方式初始化Custom c = Custom({myBool: true,myInt:2});这个方法可以不同顺序初始化,参数数量需要一致,同样忽略 mapping 访问与赋值Custom c; c.myBool = true;限制结构体仅支持合约内部使用或者继承合约使用。 如果要在参数和返回值中使用结构体,函数必须声明 internal,当然在新版本中可能限制就解除了。 function interFunc(Custom c) internal{} |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |